const HOST = require('../../../config.js').host

let app = getApp();
let getTime = require('../../../utils/util.js').formatTime
// let fullCutCounter = 0;//满减计数器，只减一次，大于0不减    
Page({
  data: {
    ceil: 0,
    total: 0,
    goodsTotal: 0,
    postage: 0,
    needPost: true,
    selectStore: false,
    checkIdx: 0,
    defaultAddress: 0,
    isHidden: true,
    viewHeight: "100rpx",
    proCoupons: [],
    totalCoupons: 0,
    phoneNumber: "",
    upperLimit: 0,
    zhongjiangCash: 0,
    useTicket:'0',
    TicketInfo:'',
    typeIdx:0,
    orderId:"",
    noticeInfo:"",
    form: {
        linkman: '',
        linkmanPhone: '',
        linkmanIdentity: '',
        address: '',
        code: '',
        province: '',
        city: '',
        area: '',
        isDefault: 0
    },
    userMessage:'',
    isFullCut: true,
    fullCut: 0,
    fullCutVal: 0,
    formId:'',
    isChoose:true,
    pakgeList:[],
  },
  changeState (e){
    let that = this;
    console.log(e)
    let {
      cindex,
    } = e.currentTarget.dataset;
    console.log(cindex)
    let pakgeList = that.data.pakgeList;
    console.log(pakgeList)
    let amount = 0;
    if ( pakgeList[cindex].isChoose == false ){
      amount = pakgeList[cindex].number * pakgeList[cindex].productPrice;
      pakgeList[cindex].isChoose = true;
    }
    else if (pakgeList[cindex].isChoose == true){
      amount = -(pakgeList[cindex].number * pakgeList[cindex].productPrice);
      pakgeList[cindex].isChoose = false;
    }
    
    that.setData({
      total : that.data.total +amount
    })
  },
  // sumPrice(){
  //   let that = this;
  //   let amount = 0;
  //   let total = that.data.total;
  //   let pakgeList = that.data.pakgeList;
  //   for (let i=0 ; i < pakgeList.length ;i++ ){
  //     pakgeList[i].isChoose
  //   }
  // }
  // ,
  getPakgeList(productId){
    let that = this;
    let pakgeList = [];
    wx.request({
      url: `${HOST }v1/giftproduct/getListByProductId/${productId}` ,
      success:res=>{
        pakgeList = res.data.data
        console.log(pakgeList)
        let len = pakgeList.length;
        if(len == 0) return;
        for (let i = 0; i < len; i++) {
          i == 0 ? pakgeList[0].isChoose = true : pakgeList[i].isChoose = false;
          pakgeList[i].number = 1;
        }
        that.setData({
          pakgeList,
          total: that.data.total + pakgeList[0].productPrice
        });

      }
    })
   

  },
  changeNumber(e){
    console.log(e)
    let pakgeList = this.data.pakgeList;
    let {
      cindex,
      type
    } = e.currentTarget.dataset;
    if (pakgeList[cindex].number == 1 && type == 'down' ) return;
    if (type == 'up'){
      pakgeList[cindex].number = pakgeList[cindex].number + 1;
    }
    if (type == 'down' && pakgeList[cindex].number > 1) {
      pakgeList[cindex].number = pakgeList[cindex].number - 1;
      
    }
    this.setData({
      pakgeList,
      total: this.sumP(pakgeList[cindex].productPrice, pakgeList[cindex].number, cindex, type, pakgeList[cindex].isChoose)
    })
  },
  sumP(productPrice,cNumber,cindex,type,isChoose){
    let that = this;
    let total = that.data.total;
    let amount = 0 ;
    if (isChoose == false ) return that.data.total  ; 
    if(type == 'up'){
      amount = productPrice + total
    } else if (type == 'down' ){
      amount = -productPrice + total
    }
    return amount;
  },
  // 表单处理
  inputName(e) {
    this.setData({
      'TicketInfo.linkman': e.detail.value
    })
  },

  inputPhone(e) {
    this.setData({
      'TicketInfo.linkmanPhone': e.detail.value
    })
  },
  inputIdentity(e) {
    this.setData({
      'TicketInfo.linkmanIdentity': e.detail.value
    })
  },
  // 储存formId
  sendFormId(e) {
    console.log(e)
    wx.request({
      url: `${HOST}v1/formid/saveFormId`,
      method: 'POST',
      data: {
        userId: app.userId,
        formId: e.detail.formId
      },
      success: res => {
        console.log(res, '插入')
      }
    })
  },
  /**
   * 选择地址
   */
  check(e) {
    let idx = e.currentTarget.dataset.idx
    this.selectAddress(idx)

  },

  selectAddress(idx) {
    app.globalData.order.address = this.data.addresses[idx]
    let self = this
    let area = this.data.addresses[idx].areaCode
    let phoneNumber = this.data.addresses[idx].linkmanPhone ? this.data.addresses[idx].linkmanPhone : this.data.addresses[idx].userMobile
    if (this.data.useTicket !== '1') { 
      this.getPostage(area)
      }
    this.setData({
      'TicketInfo.linkmanPhone' : phoneNumber,
      'TicketInfo.linkman': this.data.addresses[idx].userName,
      'TicketInfo.linkmanIdentity': this.data.addresses[idx].userCode,
      checkIdx: idx,
      selectStore: false,
      phoneNumber
    });
    if (this.data.useTicket !== '1'){
    self.userGetPhoneNmuber(area)
    }
    
  },

  selectStore() {
    this.setData({
      checkIdx: -1,
      selectStore: true,
      total: this.data.goodsTotal
    });
  },

  /**
   * 根据地区获取邮费
   */
  getPostage(area) {
    let self = this
    
    if (isNaN(area)){
      self.setData({
        postage: 5
      })
    }else{
    
      wx.request({
      url: HOST + 'v1/postage/queryPostage/' + area,
      method: 'GET',
      success: function (res) {
        if (res.data.sysCode === 1) {
          self.userGetPhoneNmuber(area)
          self.setData({
            postage: res.data.data
          })
        }
      }
    })
    }
  },

  /**
   * 滑动处理
   */
  touchstart(e) {
    this.setData({
      x: e.changedTouches[0].pageX,
      touchIdx: e.currentTarget.dataset.idx
    })
  },

  touchend(e) {
    let idx = parseInt(e.currentTarget.dataset.idx);
    let curX = e.changedTouches[0].pageX
    if (this.data.x - curX > 50) {
      this.slideLeft()
    } else if (curX - this.data.x > 50) {
      this.slideRight()
    }
  },

  slideLeft() {
    let animation = wx.createAnimation({
      duration: 200,
      timingFunction: 'ease-out', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
      delay: 0,
      transformOrigin: '50% 50% 0',
    })
    animation.left(-120).step()
    this.setData({
      animation: animation.export()
    })
  },

  slideRight() {
    let animation = wx.createAnimation({
      duration: 200,
      timingFunction: 'ease-out', // "linear","ease","ease-in","ease-in-out","ease-out","step-start","step-end"
      delay: 0,
      transformOrigin: '50% 50% 0',
    })
    animation.left(0).step()
    this.setData({
      animation: animation.export()

    })
  },

  /**
   * 删除地址
   */
  deleteAddress(e) {
    let self = this
    let id = e.currentTarget.dataset.id

    wx.showModal({
      title: '删除地址',
      content: '确定要删除这个地址吗？',
      success: function (res) {
        if (res.confirm) {
          wx.showToast({
            title: '正在删除中...',
            icon: 'loading',
            duration: 5000
          })
          if(self.data.useTicket == '1'){
            wx.request({
              url: `${HOST}v1/ticketrecord/deleteById`,
              method:'POST',
              data:{
                id:id
              },
              success:res=>{
                if (res.data.sysCode === 1) {
                  self.slideRight()
                  wx.hideToast()
                  wx.showToast({
                    title: '删除成功！',
                    icon: 'success',
                    duration: 1000
                  })
                  let addresses = self.data.addresses
                  addresses.splice(e.currentTarget.dataset.idx, 1)
                  self.setData({
                    addresses
                  })
                } else {
                  wx.hideToast()
                  wx.showToast({
                    title: '删除失败',
                    icon: 'loading',
                    content: '删除地址失败，请重试！',
                    duration: 1000
                  })
                }
              }
            })
          }
          else{
          wx.request({
            url: HOST + 'v1/userAddress/' + id,
            method: 'DELETE',
            success: function (res) {
              if (res.data.sysCode === 1) {
                self.slideRight()
                wx.hideToast()
                wx.showToast({
                  title: '删除成功！',
                  icon: 'success',
                  duration: 1000
                })
                let addresses = self.data.addresses
                app.globalData.order.address = null;
                addresses.splice(e.currentTarget.dataset.idx, 1)
                self.setData({
                  addresses
                })
              } else {
                wx.hideToast()
                wx.showToast({
                  title: '删除失败',
                  icon: 'loading',
                  content: '删除地址失败，请重试！',
                  duration: 1000
                })
              }
            },
            fail() {
              wx.hideToast()
              wx.showToast({
                title: '删除失败',
                icon: 'loading',
                content: '删除地址失败，请重试！',
                duration: 1000
              })
            }
          })
          }
        }
      }
    })
  },

  navBack() {
    wx.navigateBack({
      delta: 1
    })
  },
  sendFormMsg(e){
    let self = this;
    self.setData({
      formId:e.detail.formId
    })
    console.log(e)
  },
  /**
   * 去支付
   */
  navToPayment() {
    console.log(this.data)
    let self = this
    let order = {
      userId:""
    }
    let _order = app.globalData.order
    console.log(this.data.TicketInfo)
    if(this.data.useTicket == '1'){
      _order.address = this.data.TicketInfo
  // 储存联系方式
      wx.request({
        url: `${HOST}v1/ticketrecord/saveTicket`,
        method: 'POST',
        data: {
          userId: app.userId,
          userName: self.data.TicketInfo.linkman,
          userMobile: self.data.TicketInfo.linkmanPhone,
          userCode: self.data.TicketInfo.linkmanIdentity,
          recordStatu: 'A'
        },
        header: {
          'content-type': 'application/json'
        },
        success: (res) => {
          console.log(res);
        }
      })
      if (!_order.address.linkmanPhone){
        wx.showModal({
          title: '提交订单',
          content: '请填写正确信息',
          showCancel: false,
          success(res) {
            if (res.confirm) {
              
            }
          }
        })
        return
      }
    }
    console.log(_order.address)
    
    if (!_order.address) {
      wx.showModal({
        title: '提交订单',
        content: '请选择地址',
        showCancel: false,
        success(res) {
          if (res.confirm) {

          }
        }
      })
      return
    }

    // 合并order.address
    for (let key in _order.address) {
      order[key] = _order.address[key]
    }
    order.addressId = order.id
    console.log(order)
    delete order.id
    console.log(`地址ID：${order.addressId}`)
    
    
    // 计算规格字符串
    order.userIndentProduct = _order.goods.map(v => {
      let productName = v.productName + ' ' + v.productSpec.map((val, index) => {
        return val.specName + ' ' + val.productSpecItem[v.selectedCategory[index]].itemName
      }).join(' ')

      return {
        productId: v.id,
        payCount: v.amount,
        payUnitPrice: v.total,
        payTotalPrice: v.amount * v.total,
        productName,
        status: 1
      }
    })
    // 计算总价total
    order.totalPrice = this.data.total;
    // userId
    order.userId = app.userId
    if(self.data.useTicket =='1'){
      order.linkman = this.data.TicketInfo.linkman
      order.linkmanPhone = this.data.TicketInfo.linkmanPhone
    }
    else{
    // 是否自提
    order.isPost = this.data.selectStore ? 1 : 0
    // 运费
    order.postage = this.data.needPost ? this.data.postage : 0
    }
     // 二维码参数
    const qrcode = wx.getStorageSync('qrcode');
    console.log('保存着的二维码参数：', qrcode);
    if (qrcode) {
      order.channelType = qrcode.key;
      order.channelObj = qrcode.value;

    }
    console.log(1,order)
    order.userIndentProduct[0].productName += self.getGiftName(self.data.pakgeList)
    // 获取订单号，提交支付信息
    wx.request({
      url: HOST + 'v1/userIndent',
      data: order,
      method: 'POST',
      success: function (res) {
        if (res.data.sysCode === 1) {
            self.setData({
              orderId: res.data.sysDate
            })
            console.log(res)
          let orderId = res.data.data
          wx.showModal({
            title: '支付',
            content: '现在就去支付',
            success(res) {
              if (res.confirm) {
                self.requestPayParams(orderId)
              }
            }
          })
        }
      }
    })

  },
  // 获取礼包名称
  getGiftName(pakgeList){
    let str = '';
    for(let i = 0 ; i < pakgeList.length ;i++){
      pakgeList[i].isChoose == true ? str += '+'+ pakgeList[i].productName : str = str ;
    }
    console.log(str)
    return str
  },

  /**
   * 向后端请求支付参数
   */
  requestPayParams(orderId) {
    let self = this;

    wx.request({
      url: HOST + 'v1/pay/' + orderId,
      method: 'POST',
      success: function (res) {
        if (res.data.sysCode === 1) {
          self.pay(res.data.data)
        }
      }
    })
  },
  
  /**
   * 支付
   */
  pay(params) {
    let self = this
    
    // 正式版支付
    wx.requestPayment({
      timeStamp: params.timeStamp,
      nonceStr: params.nonceStr,
      package: 'prepay_id=' + params.prepayId,
      signType: 'MD5',
      paySign: params.sign,
      success(res) {
       
            // 支付成功推送模板消息
            wx.request({
              url: `${HOST}/v1/pushmessage/sendPayInfo`,
              method:'POST',
              data:{
                openId:app.userId,
                formId:self.data.formId,
                indentCode:self.data.orderId,
                payTime: getTime(new Date()),
                price:self.data.total
              },
              success:res=>{
                console.log('formid',self.data.formId,'openId',app.userId,'price',self.data.total)
                console.log(res);
                console.log('我成功了')
              }
            })
            // 优惠券失效
            if (self.data.useTicket == '1') {
              // 发送短信给管理员
              // console.log('进去了')
              let noticeInfo = JSON.parse(self.data.noticeInfo);
              let {
                theDay,
                ticketType,
                amount,
              } = noticeInfo;
              // theDay = `"${String(theDay)}"`;
              // ticketType = `"${String(ticketType)}"`;
              // amount = `"${String(amount)}"`;
              console.log(theDay,ticketType,amount,1)
              let userMessage = self.data.userMessage || "无";
              let linkman = self.data.TicketInfo.linkman || "无";
              let linkmanPhone = self.data.TicketInfo.linkmanPhone || "无";
              let linkmanIdentity = self.data.TicketInfo.linkmanIdentity || "无";
              // console.log( noticeInfo,userMessage, linkman, linkmanPhone, linkmanIdentity)
              wx.request({
                url: `${HOST}v1/sendordermessage`,
                method:'POST',
                data:{
                  userName:linkman,
                  mobile:linkmanPhone,
                  userCode:linkmanIdentity,
                  useTime:theDay,
                  ticketType:ticketType,
                  num:amount,
                  userMessage:userMessage,
                  carNumber:app.codeId || '无',
                },
                success: function (res) {
                  console.log(res)
                },
                complete:()=>{
                  wx.reLaunch({
                    url: '../ticket_detail/ticket_detail',
                  })
                },
                
              })

              
  
            }else{
              
              wx.request({
                url: `${HOST}v1/sendordermessage`,
                method: 'POST',
                data: {
                  userName: self.data.addresses[self.data.checkIdx].linkman,
                  mobile: self.data.addresses[self.data.checkIdx].linkmanPhone,
                  userCode: '无',
                  useTime: '无',
                  ticketType: '无',
                  num: '无',
                  userMessage: '无',
                  carNumber: app.codeId || '无',
                },
                success: function (res) {
                  console.log(res)
                }
              })
              wx.switchTab({
                    url: '../../home/home'
                  })
            }
            let proCoupons = self.data.proCoupons;
            for (var i = 0; i < proCoupons.length; i++) {
              self.loseEfficacy(proCoupons[i].id)
            }
            console.log(res.confirm)
            if (res.confirm) {
              let cart = wx.getStorageSync('cart');

              // 支付成功后删除购物车中的商品
              let cartIdx = self.data.cartIdx
              if (cartIdx) {
                for (let i = cartIdx.length - 1; i >= 0; i--) {
                  if (cartIdx[i]) {
                    cart.splice(cartIdx[i], 1)
                  }
                }
              
              } else {
               
                cart.pop()
              }

              wx.setStorage({
                key: 'cart',
                data: cart
              })
            }
    //支付成功提交用户信息（统计分销）
            wx.request({
              url: HOST + 'v1/scanrecord/saveScanRecord',
              data: {
                userId: app.userId,
                recordType: "B",
                totalPrice: self.data.total
              },
              method: 'POST'
            })

        //   }
        // })
      },
      fail(res) {
        wx.showModal({
          title: '支付结果',
          content: '支付失败，请重试！',
          success(res) {
            if (res.confirm) {
              self.pay(params)
            }
          }
        })
      }
    })
  },

  /**
   * 跳转到地址修改页
   */
  navToAddress(event) {
    let init = 0

    if (!this.data.addresses.length) {
      init = 1
    }

    let type = event.currentTarget.dataset.type
    let id = event.currentTarget.dataset.id
    wx.navigateTo({
      url: `../address/address?type=${type}&id=${id}&init=${init}&useTicket=${this.data.useTicket}`
    })
  },

  /**
   * 获取地址列表
   */
  getAddresses(userId) {
    // 买票地址
    let self = this
    if(self.data.useTicket == '1'){
      wx.request({
        url: `${HOST}v1/ticketrecord/findByUserId/${app.userId}`,
        success:res=>{
          
          self.setData({
            addresses:res.data.data,
          })
        
        },
        complete() {
          if (self.data.addresses.length > 0){
            self.selectAddress(self.data.addresses.length-1)
          }
        }
      })
     
    }
    else{
      // 正常商品地址
      wx.request({
      url: HOST + 'v1/userAddress/getListByUserId/' + app.userId,
      method: 'GET',
      success: function (res) {
        if (res.data.sysCode === 1) {

          let addresses = res.data.data.map(v => {
            return {
              id: v[0],
              linkman: v[2],
              linkmanPhone: v[3],
              address: v[7],
              code: v[8],
              province: v[11],
              city: v[12],
              area: v[13],
              areaCode: v[6],
              isDefault: v[10]
            }
          })
          
          if (addresses.length > 0) {
            
            self.setData({
              phoneNumber: addresses[0].linkmanPhone,
            }) 
          }
          self.setData({
            addresses
          })
          console.log(self.data.addresses)
        }
      },

      complete() {
        if (self.data.addresses.length > 0) {
          self.selectAddress(self.data.defaultAddress)
        }
      }
    })
    }
    
  },
  /** 获取中奖电话号码**/
  userGetPhoneNmuber() {
    let self = this
    let phoneNumber = self.data.phoneNumber;
    wx.request({
      url: HOST + 'v1/wininfo/getwininfo/' + phoneNumber,
      method: 'GET',
      success: function (res) {
        if (res.data.sysCode === 1) {
          if (res.data.data !== null) {
            self.setData({
              upperLimit: res.data.data.minLevel,
              zhongjiangCash: res.data.data.totalMoney
            })
            //  console.log(self.data.zhongjiangCash + "1000000000000000000000");
          }
          else {
            self.setData({
              phoneNumber: "",
            })

          }

          let total
          let phoneNumber = self.data.phoneNumber;
          let upperLimit = self.data.upperLimit;
          let zhongjiangCash = self.data.zhongjiangCash;
          if (self.data.needPost) {
            total = self.data.goodsTotal + self.data.postage;
          } else {
            total = self.data.goodsTotal;
          }
          if (phoneNumber.length > 0) {
            if (total > upperLimit) {
              total = total - zhongjiangCash;
            }
          }
          //判断优惠后总价格是否满足满减条件
          // let total = self.data.total;
          // if (fullCutCounter == productCount) {
            if (total >= 999) {
              total -= 90;
              self.setData({
                isFullCut: false,
                fullCut: 999,
                fullCutVal: 90,
                total: total
              })
            } else if (total >= 599) {
              total -= 50;
              self.setData({
                isFullCut: false,
                fullCut: 599,
                fullCutVal: 50,
                total: total
              })
            } else if (total >= 299) {
              total -= 20;
              self.setData({
                isFullCut: false,
                fullCut: 299,
                fullCutVal: 20,
                total: total
              })
            } else {
              self.setData({
                isFullCut: true,
                fullCut: 0,
                fullCutVal: 0
              })
            }
          // }


          self.setData({
            // 测试
            total
          })
       


        }
      }
    })

  },
  // 一键获取地址
  getWxAdress() {
    let self = this;
    if (wx.chooseAddress) {

      wx.chooseAddress({

        success: function (res) {

          console.log(JSON.stringify(res))
          let form = {
            linkmanPhone: res.telNumber,
            linkman: res.userName,
            address: `${res.provinceName + res.cityName + res.countyName + res.detailInfo}`,
            code: res.postalCode,
            province: res.provinceName,
            city: res.cityName,
            area: res.countyName,
            isDefault: 0
          };

          wx.request({
            url: HOST + 'v1/userAddress',
            data: Object.assign({}, form, { userId: app.userId }),
            method: 'POST',
            success: function (res) {
              if (res.data.sysCode === 1) {
                wx.hideToast()
                wx.showModal({
                  title: '获取地址成功',
                  content: '获取地址成功!',
                  showCancel: false,
                  success(res) {
                    self.getAddresses();
                  }
                })
              } else {
                wx.hideToast()
                wx.showToast({
                  title: '保存失败',
                  content: '保存地址失败，请重试！',
                  showCancel: false
                })
              }
            }
          })

        },

        fail: function (err) {

          console.log(JSON.stringify(err))

        }

      })

    } else {

      console.log('当前微信版本不支持chooseAddress');

    }
  },
  /** 生命周期 **/
  onLoad(options) {
    // fullCutCounter = 0; //初始满减计数
    let goods = app.globalData.order.goods // 获取订单商品
    for (var i = 0; i < goods.length; i++) {

      this.getCouponsNumber(goods[i].id, goods.length); // ----------------------------------- 循环遍历有无优惠券
    }
    // 规格序列化
    goods.forEach(v => {
      v.category = v.productSpec.map((spec, idx) => {
        return spec.productSpecItem[v.selectedCategory[idx]].itemName
      }).join('  ')
    })

    const ceil = app.globalData.ceil // 免邮标准
    const goodsTotal = new Number(options.total) // 获取从上一页面传递过来的总价
    var totalCoupons = this.data.totalCoupons;
    let cartIdx
    if (options.cartIdx) {
      cartIdx = options.cartIdx.split(',')
    }
    let total = goodsTotal - totalCoupons;
    let needPost = false
    if (total < ceil) {
      needPost = true
    }
    this.setData({
      amount:options.amount,
      typeIdx: options.typeIdx,
      ceil,
      needPost,
      total,
      goods,
      goodsTotal,
      cartIdx,
      useTicket: options.useTicket,
      noticeInfo:options.noticeInfo
    });
    if (options.useTicket) this.getPakgeList(options.productId);
  },

  onShow() {
    this.getAddresses()

  },

  /**获得优惠券并且对界面进行设置 */
  getCouponsNumber(productId,productCount) {
    let self = this;
    var allProCoupons = this.data.proCoupons;
    console.log(productId);

    let userId = app.userId;
    wx.request({
      url: HOST + 'v1/coupons/findByUserIdAndProductId/' + userId + "," + productId,
      method: "GET",
      success(res) {
        if (res.data.sysCode === 1) {
          //
          // fullCutCounter++;
          if (res.data.data != null) {
            self.sumCoupons(res.data.data.couponValue);
            allProCoupons.push(res.data.data);

          }
          if (allProCoupons.length > 0) {
            self.setData({
              proCoupons: allProCoupons,
              isHidden: false,
              viewHeight: "200rpx",
            })
          }
        }
      }
    })
  },
  /**优惠券失效请求 */

  loseEfficacy(couponsId) {
    let userId = app.userId;
    let self = this;
    wx.request({
      url: HOST + 'v1/usercoupons/useCouponById',
      method: 'POST',
      data: {
        userId: app.userId,
        couponId: couponsId
      },
      success: function (res) {
        if (res.data.sysCode === 1) {
          self.setData({
            proCoupons: [],
            totalCoupons: 0,
            isHidden: true,
            viewHeight: "100rpx",
          })
        }
      }
    })
  },

  /**中奖失效*/
  loseEfficacyForzzhongjiang() {
    let self = this;
    let phoneNumber = self.data.phoneNumber;

    if (phoneNumber.length > 0) {
      wx.request({
        url: HOST + 'v1/wininfo/updatestatus/',
        method: 'POST',
        data: {
          mobile: phoneNumber,
        },
        success: function (res) {
          console.log(res);
          console.log(res.data);
          if (res.data.sysCode === 1) {
            console.log("中奖失效")
          }
        }
      })
    }
  },


  sumCoupons(value) {
    let that = this;
    var total = this.data.total;

    var totalCoupons = this.data.totalCoupons;
    totalCoupons += value;
    total -= value;
    this.setData({
      totalCoupons: totalCoupons,
      total: total,
      goodsTotal: total,

    })
  },

  inputMark:function(e) {
    let that = this;
    let val = e.detail.value;
    that.setData({
      userMessage:val
    })
   
  }
})